﻿@model ESN.Models.Group

@{
    ViewBag.Title = "Settings";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#Groups").accordion({
            autoHeight: false,
            navigation: true
        });
        var fPermission = parseInt($("#WallPermission").val().charAt(0));
        var uPermission = parseInt($("#WallPermission").val().charAt(1));
        var gPermission = parseInt($("#WallPermission").val().charAt(2));
        if (fPermission > 2) {
            $("#frw").attr("checked", true);
            $("#fpw").attr("checked", true);
        } else if (fPermission == 2) {
            $("#fpw").attr("checked", true);
        } else if (fPermission == 1) {
            $("#frw").attr("checked", true);
        }

        if (uPermission > 2) {
            $("#urw").attr("checked", true);
            $("#upw").attr("checked", true);
        } else if (uPermission == 2) {
            $("#upw").attr("checked", true);
        } else if (uPermission == 1) {
            $("#urw").attr("checked", true);
        }

        if (gPermission == 1) {
            $("#grw").attr("checked", true);
        }
        $(".wallPermissionCheckbox").change(function () {
            var f = 0;
            var u = 0;
            var g = 0;

            if ($("#frw").is(":checked"))
                f = f + 1;
            if ($("#fpw").is(":checked"))
                f = f + 2;

            if ($("#urw").is(":checked"))
                u = u + 1;
            if ($("#upw").is(":checked"))
                u = u + 2;

            if ($("#grw").is(":checked"))
                g = g + 1;

            $("form").valid();
            $("#WallPermission").val(f.toString() + u.toString() + g.toString());
        });
        $("a#changeAvatar").click(function () {
            window.open('/Group/UpdateAvatar/@Model.GId', null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
            return false;
        });
    });
</script>
<h2>Settings</h2>
@using (Html.BeginForm("Settings", "Group"))
{
    <b>asdasd</b>
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Group</legend>
        @Html.HiddenFor(model => model.GId)
        @Html.HiddenFor(model => model.OwnerId);
        <div class="editor-label">
            @Html.LabelFor(model => model.GName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.GName)
            @Html.ValidationMessageFor(model => model.GName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.GDescription)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.GDescription)
            @Html.ValidationMessageFor(model => model.GDescription)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Avatar)
        </div>
        <div class="editor-field">
            <div><img src="@Model.Avatar" width="120" height="150" alt="*" /></div>
            <a id="changeAvatar">Change Avatar</a>
            @Html.HiddenFor(model => model.Avatar)
            @Html.ValidationMessageFor(model => model.Avatar)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.GPermission)
        </div>
        <div class="editor-field">
            <table>
                <tr>
                    <td>Invite Only</td>
                    <td>Accept Request</td>
                    <td>Free to join</td>
                </tr>
                <tr>
                    <td>@Html.RadioButtonFor(model => model.GPermission, 0)</td>
                    <td>@Html.RadioButtonFor(model => model.GPermission, 1)</td>
                    <td>@Html.RadioButtonFor(model => model.GPermission, 2)</td>
                </tr>
            </table>
            @Html.ValidationMessageFor(model => model.GPermission)
        </div>


        <div class="editor-field">
            <input id="OwnerId" name="OwnerId"  type="hidden" value="@ViewBag.UserId" />
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.WallPermission)
        </div>
        <div class="editor-field">
            <table style="text-align:center;">
                <thead>
                    <tr>
                        <th></th>
                        <th>Xem Wall</th>
                        <th>Post Wall</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>Thành viên</td>
                        <td><input id="frw" type="checkbox" class="wallPermissionCheckbox" /></td>
                        <td><input id="fpw" type="checkbox" class="wallPermissionCheckbox" /></td>
                    </tr>
                    <tr>
                        <td>Người dùng</td>
                        <td><input id="urw" type="checkbox" class="wallPermissionCheckbox" /></td>
                        <td><input id="upw" type="checkbox" class="wallPermissionCheckbox" /></td>
                    </tr>
                    <tr>
                        <td>Khách</td>
                        <td><input id="grw" type="checkbox" class="wallPermissionCheckbox" /></td>
                        <td><input type="checkbox" disabled="disabled" /></td>
                    </tr>
                </tbody>
            </table>
            @Html.HiddenFor(model => model.WallPermission)
            @Html.ValidationMessageFor(model => model.WallPermission)
        </div>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}
